/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Main.java
 *
 * Created on 28.05.2011, 6:47:53
 */
package com.softserve.fproject.dispatcher.view;

import com.softserve.fproject.dispatcher.model.FlightManager;
import com.softserve.fproject.services.FlightServiceStub.Flight;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import org.jdesktop.application.Application;

/**
 *
 * @author Den
 */
public class Main extends javax.swing.JPanel {

    /** Creates new form Main */
    public Main() {
        Application app = Application.getInstance();
        org.jdesktop.application.ResourceMap resourceMap = app.getContext().getResourceMap(Main.class);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

        setName("Form"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(getCurrentFlightsTableModel());
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getAccessibleContext().setAccessibleName(null);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 839, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
        );

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/softserve/fproject/dispatcher/resources/GUI"); // NOI18N
        jTabbedPane1.addTab(bundle.getString("CURRENT_FLIGHTS"), jPanel1); // NOI18N
        jPanel1.getAccessibleContext().setAccessibleName(null);

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable2.setModel(getTimeSheduleTableModel());
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane2.setViewportView(jTable2);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 839, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(bundle.getString("TIME_SHEDULE"), jPanel2); // NOI18N
        jPanel2.getAccessibleContext().setAccessibleName(null);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 844, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    // End of variables declaration//GEN-END:variables

    private TableModel getCurrentFlightsTableModel() {
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("com/softserve/fproject/dispatcher/resources/GUI");
        return new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{bundle.getString("FLIGHT"),
                    bundle.getString("FLIGHT_DESTINATION"),
                    bundle.getString("FLIGHT_ARRIVAL"),
                    bundle.getString("FLIGHT_STATUS")});
    }

    private TableModel getTimeSheduleTableModel() {
        ResourceBundle bundle = ResourceBundle.getBundle("com/softserve/fproject/dispatcher/resources/GUI");
        return new DefaultTableModel(new String[]{
                    bundle.getString("FLIGHT_DESTINATION"),
                    bundle.getString("FLIGHT_PERIODICITY"),
                    bundle.getString("FLIGHT_OFF_TIME"),
                    bundle.getString("FLIGHT_ARRIVAL_TIME"),},
                0);
    }

    void LoadCurrentFlightsTable(){
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        model.setRowCount(0);
        for(Flight f : FlightManager.getAllFlights())
            model.addRow(new Object[]{
                f.getId()
        });
    }
}
